package com.ljb.greendao_demo;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;

import com.ljb.greendao.gen.DaoMaster;
import com.ljb.greendao.gen.DaoSession;

/**
 * Created by user on 2017/1/12.
 */

public class MyApp extends Application {
    public static MyApp instance;
    private DaoMaster.DevOpenHelper mHelper;
    private SQLiteDatabase db;
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        initDataBase();
    }

    public static MyApp getInstance() {
        return instance;
    }

    private void initDataBase() {
        mHelper = new DaoMaster.DevOpenHelper(this, "note-db", null);
        db = mHelper.getWritableDatabase();
        mDaoMaster = new DaoMaster(db);
        mDaoSession = mDaoMaster.newSession();
    }

    public SQLiteDatabase getDb() {
        return db;
    }

    public DaoSession getmDaoSession() {
        return mDaoSession;
    }


}
